<template>
  <div class='manage-issues'>
    <p class="title">{{title}}</p>

    <div class="btns-b">
      <el-button v-for="(item,index) in btnsData" :key="index" :type="item.type" class="btn-add fr" @click="item.click(item)">{{item.label}}</el-button>
      <el-upload class="upload-demo" ref="upload" accept=".xls,.xlsx"  name='fileNames' :auto-upload="true" :action="filePath" :on-success="handleChange" :show-file-list="false">
        <el-button size="small" type="primary">上传</el-button>
      </el-upload>
    </div>

    <div class="table-box">
      <Table :modelData="modelData" :listData="listData" :pageInfo="pageInfo"></Table>
    </div>
  </div>
</template>
<script>
import Table from '../../components/table'
export default {
  components: {Table},
  name: "",
  data() {
    return {
      title:"议题管理",
      filePath:PATH+"topic/import.do",
      btnsData:[
        {label:"新增",type:'primary',click:this.add},
        {label:"模板",type:'primary',click:this.download}
      ],
      modelData:[
        {myType:'index',label:"序号"},
        {myType:'normal',prop:"name",label:'议题名称',checked:true},
        {myType:'operate',label:'管理',btns:[
          {label:'编辑',click:this.edit,icon:require('../../assets/images/manageHome/edit.png')},
          {label:'删除',click:this.delete,icon:require('../../assets/images/manageIssues/delete.png')}
        ],width:"200"}
      ],
      listData:[],
      pageInfo:{
        page:1,
        total:10,
        size:10,
        changePage:this.changePage
      }
    };
  },
  methods: {
    // 新增
    add(){
      this.$store.state.add.show=true
      this.$store.state.add.OK=this.realAdd
    },
    download(){
      location.href=downloadPath+'topic/downLoad.do'
    },
    handleChange(res){
      _g.toMessage(res)
      this.getListData()
    },
    realAdd(){
      var params=this.$store.state.add.info
      delete params.id
      if(!_g.checkParams(this.modelData,this.$store.state.add.info)){
        _g.apiPost('topic/save.do',params).then(res=>{
          _g.toMessage(res)
          if(!res.error){
            this.getListData()
          }
        })
      }
    },
    edit(scope){
      this.$store.state.add.info=JSON.parse(JSON.stringify(scope.row))
      this.add()
      this.$store.state.add.OK=this.editSave
    },
    editSave(){
      var params=this.$store.state.add.info
      if(!_g.checkParams(this.modelData,this.$store.state.add.info)){
        _g.apiPost('topic/update.do',params).then(res=>{
          _g.toMessage(res)
          if(!res.error){
            this.getListData()
          }
        })
      }
    },
    // 删除
    delete(scope){
      this.$store.state.add.info.id=scope.row.id
      this.$store.state.confirmInfo.message="是否确认删除？"
      this.$store.state.confirmInfo.show=true
      this.$store.state.confirmInfo.OK=this.sureDelete
    },
    sureDelete(){
      var params={
        id:this.$store.state.add.info.id
      }
      _g.apiPost('topic/delete.do',params).then(res=>{
        _g.toMessage(res)
        if(!res.error){
          this.getListData()
        }
      })
    },

    // 翻页
    changePage(){
      // console.log(this.pageInfo)
      this.getListData()
    },

    getListData(){
      var params={
        word:"",
        status:1,//1表示分页
        currPageNo:this.pageInfo.page
      }
      _g.apiPost('meeting/getTopicList.do',params).then(res=>{
        this.pageInfo.total=res.data.total
        this.$set(this,'listData',res.data.list)
      })
    }
  },
  created() {
    this.getListData()
  }
};
</script>
<style lang="scss" scoped>
.manage-issues {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  overflow: auto;

  .title{
    font-weight: 600;
    font-size: 20px;
    background-color: #fff;
    text-indent: 20px;
    height: 60px;
    line-height: 60px;
    box-sizing: border-box;
    border-bottom: 1px solid #ebeef5;
  }
  .upload-demo {
    float: right;
    width: 90px;
    height: 40px;
    line-height: 40px;
    margin-right: 20px;
    margin-top: 12.5px;
  }
  .btns-b {
    position: absolute;
    right: 20px;
    top: 7.5px;
    z-index: 100;
  }
  .table-box{
    height: calc(100% - 60px);
  }
}
</style>